package Abou.eCommerce.eCommerce.action;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.views.jsp.ActionTag;
 
import ch.qos.logback.classic.Logger;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
 
public class ListByCategoryAction extends ActionSupport{
 

	private List<String> lists = new ArrayList<String>();
 
	//no getter method, will not include in the JSON
	private String categorie = "";
 
	public String getCategorie() {
		return categorie;
	}

	public ListByCategoryAction(){
		
	}
 
	public String execute() {
        
		
		
		/*String absolute = getClass().getProtectionDomain().getCodeSource().getLocation().toExternalForm();
	    
		
		absolute = absolute.substring(0, absolute.length()-1);
	    absolute = absolute.substring(0, absolute.lastIndexOf("/")+1);
	    String xmlPath = absolute + "webapp/images/"; 
	    System.out.println(xmlPath);
	    String os = System.getProperty("os.name");
	    if(os.indexOf("Windows") != -1) {
	        xmlPath = xmlPath.replace("/", "\\\\");
	        if(xmlPath.indexOf("file:\\\\") != -1) {
	        xmlPath = xmlPath.replace("file:\\\\", "");
	        }
	    } else if(xmlPath.indexOf("file:") != -1) {
	        xmlPath = xmlPath.replace("file:", "");
	    }

	    
		
		System.out.println("----->begin");
		//File[] files = new File("/images/"+categorie+"/").listFiles();
		System.out.println("-------> length"+files.length);
		
		

		for (File file : files) {
		    if (file.isFile()) {
		        //lists.add(file.getName());
		    	System.out.println(file.getName());
		    
		    }
		}*/
		
		
		lists.add("40408.jpg");
		lists.add("31553.jpg");
		return Action.SUCCESS;
               
        }
 
	 
	public String listContent(String catgorie){
		
		lists.add("40408.jpg");
		lists.add("31553.jpg");
		return Action.SUCCESS;
	}
	
	public List<String> getLists() {
		return lists;
	}
 
	public void setCategorie(String categorie) {
		this.categorie = categorie;
	}

	public void setLists(List<String> lists) {
		this.lists = lists;
	}
 
	
 
}